package com.asiainfo.dacp.datastash.worker.executor.adapter.datax.model.plugin;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.springframework.beans.BeanUtils;

import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
public class UnStructuredReader implements Serializable{ 
	private static final long serialVersionUID = -5546104182911565284L;

	public UnStructuredReader(){};

	public UnStructuredReader(UnStructuredReader source) {
		BeanUtils.copyProperties(source, this);
	}
	/**
	 * 目前只支持*作为文件通配符
	 */
	private List<String> path;
	private List<? extends Object> column;
	
	private String fieldDelimiter = ",";
	
	private String compress;
	private String encoding = "utf-8";
	private boolean skipHeader; 
	
	private String nullFormat = "\\N";
	
	private Map<String, Object> csvReaderConfig;
	
	public void processPath(String path){
		this.setPath(Lists.newArrayList(Splitter.on(',').split(path)));
	} 
	
	public void processColumn(List<? extends Object> cols){
		this.setColumn(cols);
	}
	 
	
	@Data 
	@NoArgsConstructor
	public static class Column{
		/**
		 * type必须填写，index/value必须选择其一。
		 */
		private String type;

		/**
		 * type = date 
		 */
		private String format; 
		
		
		public Column(String type, String format){
			this.setType(type);
			this.setFormat(format);
		} 
		
	};
	
	@Data 
	public static class IndexColumn extends Column{
		private int index;
		public IndexColumn(int index, String type, String format){
			super(type, format);
			this.setIndex(index);
		}
	}
	@Data 
	public static class ValueColumn extends Column{
		private String value;
		public ValueColumn(String value, String type, String format){
			super(type, format);
			this.setValue(value);
		}
		
	}

}
